home *** CD-ROM | disk | FTP | other *** search
- //
- // antflviui.js
- // firefox
- //
- // Created by Zak on 2008-06-16.
- // Copyright 2008-2009 Ant.com. All rights reserved.
- //
-
- var AntFlvUi =
- {
- listShown: false,
- doc: null,
- listBox: null,
- listMenu: null,
- downloadButton: null,
-
- /**
- * Initialize the class with necessary pointers
- * @param doc The browser interface
- */
- init: function (doc)
- {
- var self = AntFlvUi;
-
- self.doc = doc;
-
- self.downloadButton = new Array();
- self.downloadList = new Array();
-
- self.downloadButton.push(AntLib.ob('antToolBarDownloadButton'));
- self.downloadButton.push(AntLib.ob('ant-video-statusbar-dl-button'));
-
- self.downloadList.push(AntLib.ob('ant-video-toolbar-dllist', doc));
- self.downloadList.push(AntLib.ob('ant-video-statusbar-dllist', doc));
-
- AntWatchUrl.addWatcher(function (URI) {
- self.onChangedUrl(URI);
- });
- },
-
- /*
- * onChangedUrl: function called when the location change
- * in the browser
- * @param aURI : the new url location
- */
- onChangedUrl: function (aURI)
- {
- var self = AntFlvUi;
- self.updateDownloadButton();
- },
-
- /**
- * True if the list is shown, false if not
- */
- isShown: function ()
- {
- var self = AntFlvUi;
- return self.listShown;
- },
-
- /**
- * Remove all listItems from the ListBox
- */
- removeAll: function ()
- {
- var self = AntFlvUi;
- while (self.listBox.childNodes.length > 2)
- self.listBox.removeChild(self.listBox.childNodes[2]);
- },
-
- /**
- * Find a node using his URL
- * @param url The URL to match
- * @return item a XulNode corresponding to a XUL:ListItem
- */
- getItemByUrl: function (url)
- {
- var self = AntFlvUi;
- for (var i = 0; i < self.listBox.childNodes.length; i++)
- {
- var item = self.listBox.childNodes[i];
-
- if (url == item.childNodes[1].getAttribute("label"))
- return item;
- }
- return null;
- },
-
-
- /**
- * Disable or enable the Download button according to the content of the page
- * (if we find our tainted flvLink item in the page or not)
- */
- updateDownloadButton: function ()
- {
- var self = AntFlvUi;
- var gBrowser = AntLib.getMainWindow().getBrowser();
- var doc = gBrowser.selectedBrowser.contentDocument;
- var mode = AntPrefs.getDisplayMode();
-
- if (doc.__antflv__ && doc.__antflv__.length != 0)
- {
- for (var i in self.downloadButton)
- self.downloadButton[i].disabled = false;
-
- if (doc.__antflv__.length == 1)
- {
- for (var i in self.downloadButton)
- {
- self.downloadButton[i].setAttribute('type', '');
- self.downloadButton[i].setAttribute('oncommand', 'AntBar.onDownloadButtonClick();');
- }
- }
- else
- {
- for (var i in self.downloadButton)
- {
- self.downloadButton[i].setAttribute('type', 'menu');
- self.downloadButton[i].setAttribute('oncommand', '');
- }
-
- self.updateMenuDownload(doc);
- }
- }
- else
- {
- for (var i in self.downloadButton)
- {
- self.downloadButton[i].setAttribute('type', '');
- self.downloadButton[i].disabled = true;
- }
-
- self.cleanMenuDownload();
- }
- },
-
-
- /*
- * Update the list of videos found
- */
-
- cleanMenuDownload: function ()
- {
- var self = AntFlvUi;
- for (var i in self.downloadList)
- {
- var menuPopup = self.downloadList[i];
-
- while (menuPopup.lastChild) {
- menuPopup.removeChild(menuPopup.lastChild);
- }
- }
- },
-
- updateMenuDownload: function (doc)
- {
- var self = AntFlvUi;
- self.cleanMenuDownload();
-
- if (doc == null)
- {
- var gBrowser = AntLib.getMainWindow().getBrowser();
- doc = gBrowser.selectedBrowser.contentDocument;
- }
-
- var listflv = doc.__antflv__;
-
- for (var i in self.downloadList)
- {
- var menuPopup = self.downloadList[i];
-
- for (var i in listflv)
- {
- var flvlink = listflv[i];
- var label = flvlink.name.replace(/_/g,' ');
-
- var menuItem = self.doc.createElement('menuitem');
- var menuCellIcon = self.doc.createElement('listcell');
- var menuCellSize = self.doc.createElement('listcell');
- var menuCellOrigin = self.doc.createElement('listcell');
- var menuCellUrl = self.doc.createElement('listcell');
- var menuCellName = self.doc.createElement('listcell');
-
- var id = i;
-
- menuCellIcon.setAttribute('class', 'listcell-iconic ant-download-class');
-
- menuCellSize.setAttribute('id', 'ant-video-tb-size-'+id);
- menuCellSize.setAttribute('label', flvlink.sizeh);
-
- menuCellOrigin.setAttribute('id', 'ant-video-tb-origin-'+id);
- menuCellOrigin.setAttribute('label', flvlink.origin);
-
- menuCellUrl.setAttribute('id', 'ant-video-tb-url-'+id);
- menuCellUrl.setAttribute('label', flvlink.url);
- menuCellUrl.setAttribute('hidden', true);
-
- menuCellName.setAttribute('id', 'ant-video-tb-name-'+id);
- menuCellName.setAttribute('label', label);
-
- menuItem.appendChild(menuCellIcon);
- menuItem.appendChild(menuCellSize);
- menuItem.appendChild(menuCellOrigin);
- menuItem.appendChild(menuCellUrl);
- menuItem.appendChild(menuCellName);
-
- menuItem.setAttribute('id', 'ant-video-tb-'+id);
- menuItem.setAttribute('label', label);
- menuItem.setAttribute('oncommand', 'AntBar.onDownloadListClick('+id+');');
-
- menuPopup.appendChild(menuItem);
- }
- }
- }
- };
-